# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgbase=libgcrypt
pkgname=('libgcrypt' 'libgcrypt-devel')
pkgver=1.6.4
pkgrel=1
pkgdesc="General purpose cryptographic library based on the code from GnuPG"
arch=(i686 x86_64)
url="http://www.gnupg.org"
license=('LGPL')
depends=('libgpg-error')
makedepends=('libgpg-error-devel')
options=('!emptydirs')
source=(ftp://ftp.gnupg.org/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2
        1.5.0-win64.patch
        libgcrypt-1.6.1-msys2.patch)
sha1sums=('ed52add1ce635deeb2f5c6650e52667debd4ec70'
          'cde802ffdde619527ee47eda1fe8f3dcb0364755'
          '1313738b181e32752dcf5741a73ba207fee6e859')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"

  patch -p2 -i ${srcdir}/1.5.0-win64.patch
  patch -p1 -i ${srcdir}/libgcrypt-1.6.1-msys2.patch
  autoreconf -fi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static

  make no_undefined=-no-undefined
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_libgcrypt() {
  groups=('libraries')
  install=$pkgname.install

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*-config
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
}

package_libgcrypt-devel() {
  pkgdesc="Libgcrypt headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libgcrypt=${pkgver}" 'libgpg-error-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
}
